<template>
  <div>
    <div style="position: relative">
      <div class="filter-line b-b-d flx-row-s-c">
        <span class="item-name">状态</span>
        <span
            v-for="(item, index) in status"
            :key="index"
            class="select-item"
            :class="[index == statusSelect ? 'active' : 'normal']"
            @click="statusChange(index)"
        >
            {{ item.name }}
          </span>
        <span class="item-name">域名</span>
        <Input
            v-model.trim="domainName"
            placeholder="请填写"
            style="width: 150px"
        />
        <div
            class="user-strong-button line-button-size"
            style="margin: 0 10px 0 30px"
            @click="pageChange(1)"
        >
          搜索
        </div>
        <div class="user-normal-button line-button-size" @click="reset">
          重置
        </div>
      </div>
    </div>
    <div class="user-main-box pub-m-t-20">
      <div style="position: relative">
        <Spin :withIcon="true" v-if="loading"></Spin>

        <div class="filter-line search-result-line flx-row-bw-c">
          <span class="c-g f-14"
            >搜索结果共<span class="c-black">{{
              total != null ? ` ${total} ` : ""
            }}</span
            >条</span
          >
        </div>
        <table class="table-area">
          <thead>
            <tr>
              <th><div class="line-style" style="justify-content: center;min-width: 48px">序号</div></th>
              <th><div class="line-style">域名</div></th>
              <th><div class="line-style">DNS平台</div></th>
              <th><div class="line-style">原DNS</div></th>
              <th><div class="line-style">新DNS</div></th>
              <th><div class="line-style">修改时间</div></th>
              <th><div class="line-style">状态</div></th>
              <th><div class="line-style" style="max-width: 200px">描述</div></th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item, index) in list" :key="index">
              <td>
                <div class="line-style" style="justify-content: center;">
                  <span class="normal-f">{{
                    (page - 1) * pageSize + index + 1
                  }}</span>
                </div>
              </td>

              <td>
                <div class="line-style">
                  <span class="normal-f">{{ item.domainName }}</span>
                </div>
              </td>
              <td>
                <div class="line-style">
                  <span class="c-o f-ell-sin">{{
                    item.dnsPlatform == 0
                      ? "出售页DNS"
                      : item.dnsPlatform == 1
                      ? "第三方"
                      : "平台DNS"
                  }}</span>
                </div>
              </td>
              <td>
                <div class="line-style">
                  <span class="normal-f">
                    {{ item.oldDnsAddr ? item.oldDnsAddr : "--" }}
                  </span>
                </div>
              </td>
              <td>
                <div class="line-style">
                  <span class="normal-f">{{
                    item.newDnsAdd ? item.newDnsAdd : "--"
                  }}</span>
                </div>
              </td>
              <td>
                <div class="line-style">
                  <span>{{ item.createdTime }}</span>
                </div>
              </td>
              <td>
                <div class="line-style">
                  <span class="normal-f">
                    {{
                      item.status == 0
                        ? "未处理"
                        : item.status == 1
                        ? "处理中"
                        : item.status == 2
                        ? "处理成功"
                        : "处理失败"
                    }}
                  </span>
                </div>
              </td>
              <td>
                <div class="line-style" style="max-width: 200px">
                  <span :title="item.status === 1 ? '已提交，结果查询中' : item.remark ? item.remark : '--'" class="c-o f-ell-sin">
                    {{item.status === 1 ? '已提交，结果查询中' : item.remark ? item.remark : "--" }}
                  </span
                  >
                </div>
              </td>
            </tr>
          </tbody>
        </table>
        <Empty-State
          v-if="total != null && total == 0"
          content="未搜索到任何内容！"
        ></Empty-State>
        <div class="form-page-bottom-area flx-row-c-c">
          <Page
            :total="total"
            :current="page"
            :page-size="pageSize"
            :page-size-opts="pageSizeOpts"
            @on-change="pageChange"
            @on-page-size-change="pageSizeChange"
            show-elevator
            show-sizer
            show-total
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getDNSLogs } from "@/api/user";
export default {
  name: "VipMyOrder",
  data() {
    return {
      loading: false,
      breadCrumb: [{name: "管理中心"}, { name: "域名管理" }, { name: "DNS设置记录" }],
      status: [
        {
          name: "全部",
          value: "",
        },
        {
          name: "未处理",
          value: 0,
        },
        {
          name: "处理中",
          value: 1,
        },
        {
          name: "处理成功",
          value: 2,
        },
        {
          name: "处理失败",
          value: 3,
        },
      ],

      // 表单数据
      domainName: "",
      statusSelect: 0,

      // 分页设置
      total: null,
      pageSizeOpts: [50, 100, 200],
      pageSize: 50,
      page: 1,
      list: [],
    };
  },
  created() {
    this.getDNSLogs();
  },
  methods: {
    // 订单状态改变
    statusChange(index) {
      this.statusSelect = index;
      this.pageChange(1);
    },
    // 切换pageSize
    pageSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.pageChange(1);
    },
    // 切换页码
    pageChange(page) {
      this.page = page;
      this.getDNSLogs();
    },
    // 重置
    reset() {
      this.statusSelect = 0;
      this.domainName = "";
      this.page = 1;
      this.getDNSLogs();
    },
    // 获取列表
    async getDNSLogs() {
      this.loading = true;
      let params = {
        status: this.status[this.statusSelect].value,
        domainName: this.domainName,
        limit: this.pageSize,
        page: this.page,
      };
      let res = await getDNSLogs(params);
      if (res.code == 200) {
        if (
          this.page > 1 &&
          res.data.total <= (this.page - 1) * this.pageSize
        ) {
          this.page =
            res.data.total == 0 ? 1 : Math.ceil(res.data.total / this.pageSize);
          this.getOrder();
          return;
        }
        this.list = res.data.list;
        this.total = res.data.total;
      }
      this.loading = false;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
